'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 在线奖励
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var dataApi = require('../libs/dataApi');

/**
 * 获取在线配置
 * @param  {[type]} reward_id [description]
 * @return {[type]}           [description]
 */
exports.getOnlineConf = function (reward_id) {
    return dataApi.online.find({
        id: reward_id
    });
};

/**
 * 获取第一个奖励的配置
 * @param  {[type]} reward_id [description]
 * @return {[type]}           [description]
 */
exports.getFirstOnlineConf = function () {
    var all_online_conf = _.toArray(dataApi.online.all());
    return _.first(all_online_conf);
};

/**
 * 获取下一个奖励
 * @param  {[type]} reward_id [description]
 * @return {[type]}           [description]
 */
exports.getNextOnlineConf = function (reward_id) {
    var online_conf = null;
    dataApi.online.any(function (online_item, key) {
        if (online_item.id > reward_id) {
            online_conf = online_item;
            return true;
        } else {
            return false;
        }
    });
    return online_conf;
};

/**
 * 在线时长最大时长
 * @param  {[type]}  [description]
 * @return {[type]}  [description]
 */
exports.getOnlineMaxTime = function () {
    var all_online_conf = _.toArray(dataApi.online.all());
    return _.last(all_online_conf).id;
};
